﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Kopytko.BoardGame;
using Kopytko.GameBase;

namespace Chess.Pawns
{
    public enum ChessPawnType
    {
        Bishop,
        King,
        Knight,
        Pawn,
        Queen,
        Rook
    }

    public enum ChessPawnColor
    {
     Black,
        White,
    }

    /// <summary>
    /// Interaction logic for ChessPawn.xaml
    /// </summary>
    public partial class ChessPawn : Pawn
    {
        public Brush Bg
        {
            get { return (Brush)GetValue(BgProperty); }
            set { SetValue(BgProperty, value); }
        }

        // Using a DependencyProperty as the backing store for BoardBoxBg.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BgProperty =
            DependencyProperty.Register("BoardBoxBg", typeof(Brush), typeof(Pawn), new UIPropertyMetadata(Brushes.Transparent));

        
        public ChessPawn(BoardPlayer player, BoardPosition position, ChessPawnType type, ChessPawnColor color) : base(player, position)
        {
            InitializeComponent();
            
            
        }


        private void setType(ChessPawnType type, ChessPawnColor color)
        {
            switch (type)
            {
                case ChessPawnType.Bishop:
                    Bg = (color == ChessPawnColor.Black) ? (Brush)FindResource("BlackBishop") : (Brush)FindResource("WhiteBishop");
                    break;
                case ChessPawnType.King:
                    Bg = (color == ChessPawnColor.Black) ? (Brush)FindResource("BlackKing") : (Brush)FindResource("WhiteKing");
                    break;
                case ChessPawnType.Knight:
                    Bg = (color == ChessPawnColor.Black) ? (Brush)FindResource("BlackKnight") : (Brush)FindResource("WhiteKnight");
                    break;
                case ChessPawnType.Pawn:
                    Bg = (color == ChessPawnColor.Black) ? (Brush)FindResource("BlackPawn") : (Brush)FindResource("WhitePawn");
                    break;
                case ChessPawnType.Queen:
                    Bg = (color == ChessPawnColor.Black) ? (Brush)FindResource("BlackQueen") : (Brush)FindResource("WhiteQueen");
                    break;
                case ChessPawnType.Rook:
                    Bg = (color == ChessPawnColor.Black) ? (Brush)FindResource("BlackRook") : (Brush)FindResource("WhiteRook");
                    break;
                default:
                    throw new ArgumentOutOfRangeException("type");
            }

            grid_main.Background = Bg;
        }


        public ChessPawn(Figura figura)
        {
            InitializeComponent();

            this.X = (byte)figura.GetPozycja().GetX();
            this.Y = (byte)figura.GetPozycja().GetY();

            var color = figura.GetKolor() == Kopytko.BoardGame.Color.Black ? ChessPawnColor.Black : ChessPawnColor.White;

            if (figura is Krol)
            {
                setType(ChessPawnType.King, color);
            }
            else if (figura is Pionek)
            {
                setType(ChessPawnType.Pawn, color);
            }
            else if (figura is Wieza)
            {
                setType(ChessPawnType.Rook, color);
            }
            else if (figura is Kon)
            {
                setType(ChessPawnType.Knight, color);
            }
            else if (figura is Laufer)
            {
                setType(ChessPawnType.Bishop, color);
            }
            else if (figura is Krolowa)
            {
                setType(ChessPawnType.Queen, color);
            }
        }

    }
}
